package com.reagent.system.controller;


import com.reagent.system.entity.Merchant;
import com.reagent.system.service.MerchantService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Api(tags = "商家接口")
@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 201, message = "成功创建资源"),
        @ApiResponse(code = 400, message = "失败"),
        @ApiResponse(code = 401, message = "服务器认证失败"),
        @ApiResponse(code = 403, message = "资源不存在"),
        @ApiResponse(code = 404, message = "页面不存在"),
        @ApiResponse(code = 500, message = "服务器异常")
})
@RestController
@Slf4j
public class MerchantController {
    @Autowired
    private MerchantService merchantService;

    @ApiOperation(value = "获取申请列表", notes = "分页获取商家申请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "serachInfo", value = "查询信息", paramType = "query", dataType = "String")
    })
    @GetMapping("/getShopInfo")
    public Object getShopInfo(Integer pageSize, Integer currentPage, String serachInfo) {
        return merchantService.getShopInfo(pageSize, currentPage, serachInfo);
    }

    @ApiOperation(value = "商家申请", notes = "商家申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchant", value = "新增对象", paramType = "query", dataType = "Merchant"),
            @ApiImplicitParam(name = "photo1", value = "营业执照", paramType = "query", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "photo2", value = "法人证件", paramType = "query", dataType = "MultipartFile")
    })
    @PostMapping("/addApply")
    public Object addApply(Merchant merchant, MultipartFile photo1, MultipartFile photo2) throws Exception {
        return merchantService.addAppy(merchant, photo1, photo2);
    }

    @ApiOperation(value = "通过审核", notes = "通过审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改对象", paramType = "query", dataType = "String"),
    })
    @PatchMapping("/updateStatusToSuccess/{id}")
    public Object updateStatusToSuccess(@PathVariable("id") Integer id) {
        return merchantService.updateStatusToSuccess(id);
    }


    @ApiOperation(value = "拒绝审核", notes = "拒绝审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改对象", paramType = "query", dataType = "String"),
    })
    @PatchMapping("/updateStatusToSuccess0/{id}")
    public Object updateStatusToSuccess0(@PathVariable("id") Integer id) {
        return merchantService.updateStatusToSuccess0(id);
    }


}

